﻿using System.Collections.Generic;
using ControleRepresentante.Common;
using ControleRepresentante.Logic.Models;
using WebSite.ViewModels.Fields;
using Enum = System.Enum;

namespace WebSite.ViewModels.EditViewModels
{
    public class AttributeEditViewModel : EditViewModel
    {
        public bool IsNew { get; private set; }

        public AttributeEditViewModel(bool isNew)
            : base("Atributo")
        {
            IsNew = isNew;
        }

        protected override IEnumerable<IField> GetGeralFields()
        {
            Attribute attribute = (Attribute)Model;
            IField tipoField;
            if (IsNew)
            {
                DropDownListField dropDownListField = new DropDownListField("Tipo", "type");
                AttributeType attributeType = attribute.Type;
                foreach (AttributeType x in Enum.GetValues(typeof(AttributeType)))
                {
                    dropDownListField.Add(x.GetDescription(), x, x == attributeType);
                }
                tipoField = dropDownListField;
            }
            else
            {
                tipoField = new LabelField("Tipo", "tipo", attribute.Type.GetDescription());
            }

            List<IField> result = new List<IField>
            {
                tipoField,
                new TextBoxField("Nome", "name", attribute.Name, true),
            };

            result.AddRange(base.GetGeralFields());

            return result;
        }
    }
}